﻿$(function() {
    $("#DIALOG").dialog({
        autoOpen: false,
        bgiframe: true,
		width:761,
		height: 620,
        modal: true,
		show:'slide'
    });
});

function OnSelectTreatment(trmid)
{
	var iframe = $('#DIALOG iframe').get(0);
	var src = "HistoryStart.aspx?trmid="+trmid;
    if (iframe.src.toLowerCase().indexOf(src) < 0) {
		iframe.src = src;
	}
	setDialogParam(iframe, 500, 300, $('#DIALOG'), 540, 320, '开始治疗');
	$('#DIALOG').dialog('open');
}
function AddTreatmentHistory() {
    var iframe = $('#DIALOG iframe').get(0);
    if (iframe.src.toLowerCase().indexOf('treatmentselect.htm') <0) {
        iframe.src = "TreatmentSelect.htm";
    }
	setDialogParam(iframe, 740, 490, $('#DIALOG'), 760, 540, '选择西药治疗');
	$('#DIALOG').dialog('open');
}
function AddPresHistory(diseaseid){
    var iframe = $('#DIALOG iframe').get(0);
    var src = "prescription_selection.htm?diseaseid="+diseaseid;
    if (iframe.src.toLowerCase().indexOf(src) <0) {
        iframe.src = src;
    }
	setDialogParam(iframe, 750, 560, $('#DIALOG'), 770, 610, '选择中药治疗');
	$('#DIALOG').dialog('open');
}

function StartTreatment(trmid, startcurrent, title) {
	startcurrent = typeof(startcurrent) == "undefined" ? 1 : startcurrent ;
	title = typeof(title) == "undefined" ? "开始治疗" : title ;
	var src="historystart.aspx?trmid="+trmid+"&cur="+startcurrent;
	var iframe = $('#DIALOG iframe').get(0);
    if (iframe.src.toLowerCase().indexOf(src) < 0) {
		iframe.src = src;
	}
	setDialogParam(iframe, 500, 320, $('#DIALOG'), 540, 360, title);
    $('#DIALOG').dialog('open');
	
}

function StopTreatment(trmid){
	
	var iframe = $('#DIALOG iframe').get(0);
	var src="historystop.aspx?trmid="+trmid;
    if (iframe.src.toLowerCase().indexOf(src) < 0) {
		iframe.src = src;
	}
	setDialogParam(iframe, 460, 310, $('#DIALOG'), 500, 360, '停止治疗');
    $('#DIALOG').dialog('open');
}
function ChangeDosage(trmid){
	var iframe = $('#DIALOG iframe').get(0);
	var src="changedosage.aspx?trmid="+trmid;
    if (iframe.src.toLowerCase().indexOf(src) < 0) {
		iframe.src = src;
	}
	setDialogParam(iframe, 460, 310, $('#DIALOG'), 500, 360, '修改剂量');
    $('#DIALOG').dialog('open');
}
function DeleteTreatments(trmId, trmName){
	$.prompt("你确定要删除"+trmName+"的所有历史记录吗？", { buttons: { 确定: true, 取消:false }, focus: 1, callback:function(v, m, f){
    if(v){
        delHistory(trmId);
    }
    }});
    function delHistory(trmId){
        function OnSuc(xmlDoc) {
            $.prompt("操作成功", { buttons: { 关闭: true }, focus: 1, callback: function() {
              location.href = location.href ;
            }
            });
        }
        function OnFail(xmlDoc) {
            var result = xmlDoc.getElementsByTagName("result")[0];
            var retCode = result.getAttribute("code");
            var sMsg = result.getAttribute("msg");
            $.prompt(sMsg, { buttons: { 关闭: true }, focus: 1 });
        }
        function OnError() {
            $.prompt("操作失败，请稍后再试！", { buttons: { 关闭: true }, focus: 1 });
        }
        
        var surl = "treatHisDel.aspx?trmid=" + parseInt(trmId);
        getResultXml(surl, OnSuc, OnFail, OnError);
    }
}